package event.listen;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonEventListener implements ActionListener {
    // 外界将需要处理的窗体通过构造函数传入
    private ButtonEven be;

    public ButtonEventListener(){

    }

    public ButtonEventListener(ButtonEven be){
        this.be = be;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
   //     System.out.println("我来处理事件");

        // 得到事件源
        JButton b = (JButton) e.getSource();
        // 得到事件源的内容
        String who = b.getText();
        //System.out.println(who);

        if("变红".equals(who)){
            be.getContentPane().setBackground(Color.RED);
        }else if("变绿".equals(who)){
            be.getContentPane().setBackground(Color.GREEN);
        }
    }
}
